hallcurrent25 2.2.0
Loading...
Searching...
No Matches
hallcurrent25.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef HALLCURRENT25_H
29#define HALLCURRENT25_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
59
64
69
74#define HALLCURRENT25_INPUT_CHANNEL_VOUT 0
75#define HALLCURRENT25_INPUT_CHANNEL_VOC 1
76
81#define HALLCURRENT25_NUM_CONVERSIONS 200
82
87#define HALLCURRENT25_ADC_RESOLUTION 0x0FFF
88#define HALLCURRENT25_VREF_3V3 3.3
89#define HALLCURRENT25_VREF_5V 5.0
90#define HALLCURRENT25_VREF HALLCURRENT25_VREF_3V3
91
96#define HALLCURRENT25_TIMEOUT_MS 2000
97
106#define HALLCURRENT25_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
107#define HALLCURRENT25_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
108 // hallcurrent25_set
110
115
120
125#define HALLCURRENT25_MAP_MIKROBUS( cfg, mikrobus ) \
126 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
127 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
128 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
129 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
130 cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
131 // hallcurrent25_map // hallcurrent25
134
139typedef struct
140{
141 // Input pins
142 digital_in_t fault;
143
144 // Modules
145 spi_master_t spi;
146
147 pin_name_t chip_select;
150
152
157typedef struct
158{
159 // Communication gpio pins
160 pin_name_t miso;
161 pin_name_t mosi;
162 pin_name_t sck;
163 pin_name_t cs;
164
165 // Additional gpio pins
166 pin_name_t fault;
167
168 // static variable
169 uint32_t spi_speed;
170 spi_master_mode_t spi_mode;
171 spi_master_chip_select_polarity_t cs_polarity;
172
174
185
191
202
217
230err_t hallcurrent25_read_raw_adc ( hallcurrent25_t *ctx, uint8_t channel, uint16_t *raw_adc );
231
245err_t hallcurrent25_read_voltage ( hallcurrent25_t *ctx, uint8_t channel, float *voltage );
246
261err_t hallcurrent25_read_voltage_avg ( hallcurrent25_t *ctx, uint8_t channel, uint16_t num_conv, float *voltage_avg );
262
272
284
296err_t hallcurrent25_calib_resolution ( hallcurrent25_t *ctx, float calib_current );
297
310err_t hallcurrent25_read_current ( hallcurrent25_t *ctx, float *current );
311
312#ifdef __cplusplus
313}
314#endif
315#endif // HALLCURRENT25_H
316 // hallcurrent25
318
319// ------------------------------------------------------------------------ END
err_t hallcurrent25_read_voltage_avg(hallcurrent25_t *ctx, uint8_t channel, uint16_t num_conv, float *voltage_avg)
Hall Current 25 read average voltage level function.
err_t hallcurrent25_read_current(hallcurrent25_t *ctx, float *current)
Hall Current 25 read current function.
uint8_t hallcurrent25_get_fault_pin(hallcurrent25_t *ctx)
Hall Current 25 get FAULT pin function.
void hallcurrent25_cfg_setup(hallcurrent25_cfg_t *cfg)
Hall Current 25 configuration object setup function.
err_t hallcurrent25_read_raw_adc(hallcurrent25_t *ctx, uint8_t channel, uint16_t *raw_adc)
Hall Current 25 read raw ADC value function.
err_t hallcurrent25_read_voltage(hallcurrent25_t *ctx, uint8_t channel, float *voltage)
Hall Current 25 read voltage level function.
err_t hallcurrent25_calib_resolution(hallcurrent25_t *ctx, float calib_current)
Hall Current 25 calib resolution function.
err_t hallcurrent25_calib_offset(hallcurrent25_t *ctx)
Hall Current 25 calib offset function.
err_t hallcurrent25_init(hallcurrent25_t *ctx, hallcurrent25_cfg_t *cfg)
Hall Current 25 initialization function.
hallcurrent25_return_value_t
Hall Current 25 Click return value data.
Definition hallcurrent25.h:180
@ HALLCURRENT25_ERROR
Definition hallcurrent25.h:182
@ HALLCURRENT25_OK
Definition hallcurrent25.h:181
This file contains SPI specific macros, functions, etc.
Hall Current 25 Click configuration object.
Definition hallcurrent25.h:158
spi_master_chip_select_polarity_t cs_polarity
Definition hallcurrent25.h:171
pin_name_t sck
Definition hallcurrent25.h:162
spi_master_mode_t spi_mode
Definition hallcurrent25.h:170
pin_name_t mosi
Definition hallcurrent25.h:161
uint32_t spi_speed
Definition hallcurrent25.h:169
pin_name_t miso
Definition hallcurrent25.h:160
pin_name_t cs
Definition hallcurrent25.h:163
pin_name_t fault
Definition hallcurrent25.h:166
Hall Current 25 Click context object.
Definition hallcurrent25.h:140
spi_master_t spi
Definition hallcurrent25.h:145
float data_resolution
Definition hallcurrent25.h:149
digital_in_t fault
Definition hallcurrent25.h:142
float zero_curr_offset
Definition hallcurrent25.h:148
pin_name_t chip_select
Definition hallcurrent25.h:147